package com.plsjavaweb.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.plsjavaweb.pojo.EmployeePOJO;
import com.plsjavaweb.pojo.EmployeeSeatPOJO;
import com.plsjavaweb.pojo.LocationDetailsPOJO;
import com.plsjavaweb.pojo.LocationPOJO;
import com.plsjavaweb.pojo.ProjectPOJO;
import com.plsjavaweb.pojo.SeatPOJO;
import com.plsjavaweb.pojo.SeatTypePOJO;

public class EmployeeSeatMapper implements Mapper<EmployeeSeatPOJO>{

	//Get the List of Employees with Seat
	public List<EmployeeSeatPOJO> MapList(ResultSet rs) throws SQLException {
		List<EmployeeSeatPOJO> employeeSeats = new ArrayList<>();
		EmployeeSeatPOJO  employeeSeat = null;
		EmployeePOJO employee = null;
		SeatPOJO seat = null;
		LocationPOJO location = null;
		LocationDetailsPOJO locationDetail = null;
		ProjectPOJO project = null;
		SeatTypePOJO seatType = null;
		
		while(rs.next()){
			employeeSeat = new EmployeeSeatPOJO();
			employee = new EmployeePOJO();
			employee.setEmailAdd(rs.getString("email_add"));
			employee.setEmployeeId(rs.getInt("employee_id"));
			employee.setFirstName(rs.getString("first_name"));
			employee.setLastName(rs.getString("last_name"));
		
			location = new LocationPOJO();
			location.setLocationAddress(rs.getString("location_address"));
			location.setLocationCode(rs.getString("location_code"));
			
			locationDetail = new LocationDetailsPOJO();
			locationDetail.setFloorLevel(rs.getString("floor_level"));
			locationDetail.setLocation(location);
			
			project = new ProjectPOJO();
			project.setProjectCode(rs.getString("project_desc"));
			project.setProjectDescription(rs.getString("project_desc"));
			
			seatType = new SeatTypePOJO();
			seatType.setSeatTypeDesc(rs.getString("seat_type_desc"));
			seatType.setSeatTypeCode(rs.getString("seat_type_code"));
			
			seat = new SeatPOJO();
			seat.setSeatCode(rs.getString("seat_code"));
			seat.setCol(rs.getInt("col"));
			seat.setLocalNo(rs.getInt("local_no"));
			seat.setLocationDetail(locationDetail);
			seat.setQuadrant(rs.getString("quadrant"));
			seat.setRow(rs.getInt("row"));
			seat.setProject(project);
			seat.setSeatType(seatType);
			
			employeeSeat.setEmployee(employee);
			employeeSeat.setSeat(seat);
			
			employeeSeats.add(employeeSeat);
			
		}
		return employeeSeats;
	}

	@Override
	public EmployeeSeatPOJO MapObject(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
